//
//  ThirdViewCell.m
//  N9Mi
//
//  Created by Sunshine on 2018/7/17.
//  Copyright © 2018年 Sunshine. All rights reserved.
//

#import "ThirdViewCell.h"

@implementation ThirdViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.shopNum = 1;
        UIView *backview = [UIView new];
        backview.layer.masksToBounds = YES;
        backview.layer.cornerRadius = 5*kJLXWidthScale;
        backview.layer.borderColor =LineColor.CGColor;
        backview.layer.borderWidth = 1;
        [self.contentView addSubview:backview];
        backview.sd_layout
        .topSpaceToView(self.contentView, 10*kJLXWidthScale)
        .leftSpaceToView(self.contentView, 10*kJLXWidthScale)
        .rightSpaceToView(self.contentView, 10*kJLXWidthScale)
        .bottomSpaceToView(self.contentView, 10*kJLXWidthScale);
        
        UIImageView *imagevi = [UIImageView new];
        self.typeImagevi = imagevi;
        [backview addSubview:imagevi];
        imagevi.sd_layout
        .centerYEqualToView(backview)
        .leftSpaceToView(backview, 10*kJLXWidthScale)
        .widthIs(15*kJLXWidthScale)
        .heightIs(15*kJLXWidthScale);
        
        
        UIImageView *titimagevi = [UIImageView new];
        self.titimagevi = titimagevi;
        [backview addSubview:titimagevi];
        titimagevi.sd_layout
        .topSpaceToView(backview,10*kJLXWidthScale)
        .leftSpaceToView(imagevi,10*kJLXWidthScale)
        .heightIs(85*kJLXWidthScale)
        .widthIs(70*kJLXWidthScale);
        
        UILabel *titlab = [UILabel new];
        self.titlab = titlab;
        titlab.font = [UIFont systemFontOfSize:13*kJLXWidthScale];
        titlab.textColor = [UIColor blackColor];
        [backview addSubview:titlab];
        titlab.sd_layout
        .topSpaceToView(backview, 10*kJLXWidthScale)
        .leftSpaceToView(titimagevi, 10*kJLXWidthScale)
        .rightSpaceToView(backview, 10*kJLXWidthScale)
        .heightIs(20*kJLXWidthScale);
        
        UILabel *seclab = [UILabel new];
        self.scelab = seclab;
        self.scelab.numberOfLines = 0;
        seclab.font = [UIFont systemFontOfSize:12*kJLXWidthScale];
        seclab.textColor = [UIColor grayColor];
        [backview addSubview:seclab];
        seclab.sd_layout
        .topSpaceToView(titlab, 0)
        .leftSpaceToView(titimagevi, 10*kJLXWidthScale)
        .rightSpaceToView(backview, 100*kJLXWidthScale)
        .autoHeightRatio(0);
        
        UILabel *pricelab = [UILabel new];
        self.pricelab = pricelab;
        pricelab.font = [UIFont systemFontOfSize:15*kJLXWidthScale];
        pricelab.textColor = [UIColor orangeColor];
        [backview addSubview:pricelab];
        pricelab.sd_layout
        .topSpaceToView(seclab, 0)
        .leftSpaceToView(titimagevi, 10*kJLXWidthScale)
        .heightIs(25*kJLXWidthScale)
        .widthIs(100*kJLXWidthScale);
        
        UIView *btnview = [UIView new];
        btnview.backgroundColor = [UIColor orangeColor];
        [backview addSubview:btnview];
        btnview.sd_layout
        .topSpaceToView(titlab, 0)
        .rightSpaceToView(backview, 10*kJLXWidthScale)
        .heightIs(30*kJLXWidthScale)
        .widthIs(94*kJLXWidthScale);
        
        for (int i = 0; i < 3 ; i ++) {
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.titleLabel.font = [UIFont systemFontOfSize:15*kJLXWidthScale];
            btn.backgroundColor = [UIColor whiteColor];
            [btnview addSubview:btn];
            btn.sd_layout
            .topSpaceToView(btnview, 1)
            .leftSpaceToView(btnview, 1 + 31*kJLXWidthScale*i)
            .bottomSpaceToView(btnview, 1)
            .widthIs(30*kJLXWidthScale);
            if (i == 1) {
                self.shopnumbtn = btn;
                NSString *numStr = [NSString stringWithFormat:@"%ld",self.shopNum];
                [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
                [btn setTitle:numStr forState:UIControlStateNormal];
            }else if (i == 0){
                [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
                [btn setTitle:@"-" forState:UIControlStateNormal];
                [btn addTarget:self action:@selector(numButtonAction:) forControlEvents:UIControlEventTouchUpInside];
            }else if (i == 2){
                [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
                [btn setTitle:@"+" forState:UIControlStateNormal];
                  [btn addTarget:self action:@selector(numButtonAction:) forControlEvents:UIControlEventTouchUpInside];
            }
            btn.tag = 250 + i;
        }
        MineButton *delbtn = [MineButton buttonWithType:UIButtonTypeCustom];
        self.delebtn = delbtn;
        [delbtn setImage:[UIImage imageNamed:@"dele"] forState:UIControlStateNormal];
        [backview addSubview:delbtn];
        delbtn.sd_layout
        .topSpaceToView(btnview, 10*kJLXWidthScale)
        .rightSpaceToView(backview, 10*kJLXWidthScale)
        .heightIs(30*kJLXWidthScale)
        .widthIs(25*kJLXWidthScale);
    }
    return self;
}


-(void)numButtonAction:(UIButton *)sender{
    
    if (sender.tag - 250 == 0) {
        if (self.shopNum > 1) {
            self.shopNum --;
            UIButton *btn = [self viewWithTag:251];
            NSString *numstr = [NSString stringWithFormat:@"%ld",self.shopNum];
            [btn setTitle:numstr forState:UIControlStateNormal];
            self.shopNumBlock(self.shopNum);
        }
    }else if (sender.tag - 250 == 2){
        self.shopNum ++;
        UIButton *btn = [self viewWithTag:251];
        NSString *numstr = [NSString stringWithFormat:@"%ld",self.shopNum];
        [btn setTitle:numstr forState:UIControlStateNormal];
        self.shopNumBlock(self.shopNum);
    }
    
}

-(void)creatShopBtnNum:(NSInteger )num{
    self.shopNum = num;
    NSString *numstr = [NSString stringWithFormat:@"%ld",self.shopNum];
    [self.shopnumbtn setTitle:numstr forState:UIControlStateNormal];
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
